﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class RC_Transfers : System.Web.UI.UserControl
    {
        //*************************** Class ********************************
        private SsMng ssMng = new SsMng();
        private IPositionTypeBLL ptBLL = new PositionTypeBLL();
        private IFieldBLL fieldBLL = new FieldBLL();
        private IClassBLL cBLL = new ClassBLL();
        private IJobSiteBLL jsBLL = new JobSiteBLL();
        //*************************** Control ********************************
        private RadTextBox txttempEmployee, txtOldPosition, txtOldJobsiteName;
        private RadTextBox txtPosition, txtPosRef, txtRemarks;
        private RadNumericTextBox txtOldSalary, txtSalary;
        private Label lblBirthDate, lblCitizen, lblTmpEmpSeq;
        private RadComboBox cmbTmpEdu, movmentCombo, oldPosTypeCombo, oldClassCombo;
        private RadComboBox posTypeCombo, jobSiteCombo, classCombo;
        private RadDateInput txtStartDate;

        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            ControlConfig();
            //txtStartDate.GetType();
            
            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSequence.Text = DataBinder.Eval(DataItem, "cmd_add_seq").ToString();
                    lblTmpEmpSeq.Text = DataBinder.Eval(DataItem, "tmp_emp_seq").ToString();
                    lblCmdSeq.Text = DataBinder.Eval(DataItem, "cmd_seq").ToString();

                    txttempEmployee.Text = DataBinder.Eval(DataItem, "full_name").ToString();
                    lblBirthDate.Text = DataBinder.Eval(DataItem, "birth_date", "{0:dd/MM/yyyy}").ToString();
                    lblCitizen.Text = DataBinder.Eval(DataItem, "citizen").ToString();
                    
                    cmbTmpEdu.SelectedValue = DataBinder.Eval(DataItem, "tmp_edu_seq").ToString();
                    movmentCombo.SelectedValue = DataBinder.Eval(DataItem, "move_seq").ToString();

                    txtOldPosition.Text = DataBinder.Eval(DataItem, "old_pos_name").ToString();
                    txtOldJobsiteName.Text = DataBinder.Eval(DataItem, "old_job_site_name").ToString();
                    txtOldSalary.Text = DataBinder.Eval(DataItem, "old_salary").ToString();
                    oldPosTypeCombo.SelectedValue = DataBinder.Eval(DataItem, "old_pos_type_seq").ToString();
                    oldClassCombo.SelectedValue = DataBinder.Eval(DataItem, "old_class_seq").ToString();

                    txtPosition.Text = DataBinder.Eval(DataItem, "pos_name").ToString();
                    txtSalary.Text = DataBinder.Eval(DataItem, "salary").ToString();
                    txtPosRef.Text = DataBinder.Eval(DataItem, "pos_ref_no").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    
                    //txtStartDate.Text = DataBinder.Eval(DataItem, "start_date").ToString();
                    posTypeCombo.SelectedValue = DataBinder.Eval(DataItem, "pos_type_seq").ToString();
                    classCombo.SelectedValue = DataBinder.Eval(DataItem, "class_seq").ToString();
                    jobSiteCombo.SelectedValue = DataBinder.Eval(DataItem, "job_site_Seq").ToString();
                }
            }
        }
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        private void ControlConfig()
        {
            txttempEmployee = (RadTextBox)CMD_EmployeeInfo1.FindControl("txttempEmployee");
            lblBirthDate = (Label)CMD_EmployeeInfo1.FindControl("lblBirthDate");
            lblCitizen = (Label)CMD_EmployeeInfo1.FindControl("lblCitizen");
            lblTmpEmpSeq = (Label)CMD_EmployeeInfo1.FindControl("lblTmpEmpSeq");
            cmbTmpEdu = (RadComboBox)CMD_EmployeeInfo1.FindControl("cmbTmpEdu");
            movmentCombo = (RadComboBox)CMD_EmployeeInfo1.FindControl("movmentCombo");

            txtOldPosition = (RadTextBox)CMD_FieldPositionInfo1.FindControl("txtPosition");
            txtOldJobsiteName = (RadTextBox)CMD_FieldPositionInfo1.FindControl("txtJobSiteName");
            txtOldSalary = (RadNumericTextBox)CMD_FieldPositionInfo1.FindControl("txtSalary");
            oldPosTypeCombo = (RadComboBox)CMD_FieldPositionInfo1.FindControl("posTypeCombo");
            oldClassCombo = (RadComboBox)CMD_FieldPositionInfo1.FindControl("classCombo");

            txtPosition = (RadTextBox)CMD_NewPositionInfo1.FindControl("txtPosition");
            txtSalary = (RadNumericTextBox)CMD_NewPositionInfo1.FindControl("txtSalary");
            txtPosRef = (RadTextBox)CMD_NewPositionInfo1.FindControl("txtPosRef");
            txtRemarks = (RadTextBox)CMD_NewPositionInfo1.FindControl("txtRemarks");
            //txtStartDate = (RadDateInput)CMD_NewPositionInfo1.FindControl("txtStartDate");
            posTypeCombo = (RadComboBox)CMD_NewPositionInfo1.FindControl("posTypeCombo");
            classCombo = (RadComboBox)CMD_NewPositionInfo1.FindControl("classCombo");
            jobSiteCombo = (RadComboBox)CMD_NewPositionInfo1.FindControl("jobSiteCombo");

            Control c = (Control)CMD_NewPositionInfo1.FindControl("txtStartDate");
            txtStartDate = (RadDateInput)c.FindControl("dateinput");
            //txtStartDate.
        }
        private void bindClasscombo()
        {
            IList<ClassInfo> infoList = cBLL.ListClasses(posTypeCombo.SelectedValue);

            classCombo.DataSource = infoList;
            classCombo.DataBind();
        }

        private void bindJobSiteCombo()
        {
            IList<JobSiteInfo> infoList = jsBLL.ListJobSiteByTypes(SystemInfo._JobsiteExternal);

            jobSiteCombo.DataSource = infoList;
            jobSiteCombo.DataBind();
        }

        private void bindPosTypeCombo()
        {
            IList<PositionTypeInfo> infoList = ptBLL.ListPositionTypes(Convert.ToInt32(Session["EMPTYPE"].ToString()));

            posTypeCombo.DataSource = infoList;
            posTypeCombo.DataBind();
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            RC_TransferBLL obj = new RC_TransferBLL();

            obj.insert(Convert.ToInt32(Session["CMD"].ToString())
                , Convert.ToInt32(lblTmpEmpSeq.Text.Trim())
                , Convert.ToInt32(movmentCombo.SelectedValue)
                , Convert.ToInt32(cmbTmpEdu.SelectedValue)
                , txtOldPosition.Text.Trim()
                , Convert.ToInt32(oldPosTypeCombo.SelectedValue)
                , Convert.ToInt32(oldClassCombo.SelectedValue)
                , txtOldJobsiteName.Text.Trim()
                , Convert.ToDouble(txtOldSalary.Text)
                , Convert.ToDouble(txtSalary.Text)
                , txtPosition.Text.Trim()
                , txtPosRef.Text.Trim()
                , Convert.ToInt32(classCombo.SelectedValue)
                , Convert.ToInt32(jobSiteCombo.SelectedValue)
                , jobSiteCombo.SelectedItem.Text
                , txtStartDate.SelectedDate.Value.ToString()
                , Convert.ToInt32(posTypeCombo.SelectedValue)
                , txtRemarks.Text.Trim()
                , ssMng.EmpSeqI
                );

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            RC_TransferBLL obj = new RC_TransferBLL();

            obj.Update(Convert.ToInt32(lblSequence.Text)
                , Convert.ToInt32(lblCmdSeq.Text)
                , Convert.ToInt32(lblTmpEmpSeq.Text)
                , Convert.ToInt32(movmentCombo.SelectedValue)
                , Convert.ToInt32(cmbTmpEdu.SelectedValue)
                , txtOldPosition.Text.Trim()
                , Convert.ToInt32(oldPosTypeCombo.SelectedValue)
                , Convert.ToInt32(oldClassCombo.SelectedValue)
                , txtOldJobsiteName.Text.Trim()
                , Convert.ToDouble(txtOldSalary.Text)
                , Convert.ToDouble(txtSalary.Text)
                , txtPosition.Text.Trim()
                , txtPosRef.Text.Trim()
                , Convert.ToInt32(classCombo.SelectedValue)
                , Convert.ToInt32(jobSiteCombo.SelectedValue)
                , jobSiteCombo.SelectedItem.Text
                , txtStartDate.SelectedDate.Value.ToString()
                , Convert.ToInt32(posTypeCombo.SelectedValue)
                , txtRemarks.Text.Trim()
                , ssMng.EmpSeqI
                );
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}